<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表单</title>
    <link rel="stylesheet" href="/frame/layui/css/layui.css">
    <link rel="stylesheet" href="/frame/static/css/style.css">
    <link rel="icon" href="/frame/static/image/code.png">
</head>
<body class="body">


<blockquote class="layui-elem-quote layui-text">
    这里放公告
</blockquote>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加账户</legend>
</fieldset>

<form class="layui-form" action="" id="user-form">

    <div class="layui-form-item">
        <input type="hidden" name="login_account_id" >
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block" style="padding-right: 30px;">
            <input type="text" name="login_account_name" placeholder="输入用户名" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block" style="padding-right: 30px;">
            <input type="text" name="login_account_number" lay-verify="required" placeholder="请输入账号" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block" style="padding-right: 30px;">
            <input type="password" name="login_account_pwd" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
        <#--<div class="layui-form-mid layui-word-aux">请务必填写密码</div>-->
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block" style="padding-right: 30px;">
            <input type="password" name="login_account_pwd2" placeholder="请再次输入密码" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block" style="padding-right: 30px;">
            <input name="login_account_email" lay-verify="email" autocomplete="off" class="layui-input" type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block" style="padding-right: 30px;">
            <input name="login_account_tel" lay-verify="phone" autocomplete="off" class="layui-input" type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属角色</label>
        <div class="layui-input-block" style="padding-right: 30px;">
            <select name="login_account_role" lay-filter="required" id="role-list">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block" style="padding-right: 30px;">
            <select name="login_account_state" lay-filter="required">
                <option value="">请选择</option>
                <option value="0">正常</option>
                <option value="1">冻结</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-top: 70px;" >
            <button class="layui-btn" style="text-align: center;margin-left: 50px;" lay-submit lay-filter="demo1">保存</button>
            <button class="layui-btn layui-btn-primary" id="back-btn"  style="text-align: center;margin-left: 50px;">返回</button>
        </div>
    </div>

</form>

<script src="/frame/layui/layui.js" charset="utf-8"></script>
<script>
    var data = parent.rowJSONDate;
    layui.use(['form','layer'], function(){
        var form = layui.form
                ,$ = layui.jquery
                ,layer = layui.layer;

        $.ajax({
            url: "/role/query",
            data:{"account_role_name":null,"limit":9999},
            type: "post",
            dataType: "json",
            success: function (result) {
                $("#role-list").empty();
                var li = "<option value=''>请选择</option>"
                $.each(result.data,function(i,item){

                    if(data!= null && data != ''){
                        if(item.account_role_id == data.login_account_role){
                            li += "<option value='"+item.account_role_id+"' selected >"+item.account_role_name+"</option>";
                        }else {
                            li += "<option value='"+item.account_role_id+"' >"+item.account_role_name+"</option>";
                        }
                    }else{
                        li += "<option value='"+item.account_role_id+"' >"+item.account_role_name+"</option>";
                    }

                })
                $("#role-list").append(li);
                form.render("select")
            }
        });

        if(data!=null){
            $("#save-title").text("修改账户");
            $("input[name='login_account_id']").val(data.login_account_id);
            $("input[name='login_account_number']").val(data.login_account_number);
            $("input[name='login_account_name']").val(data.login_account_name);
            $("input[name='login_account_pwd']").val(data.login_account_pwd);
            $("input[name='login_account_pwd2']").val(data.login_account_pwd);
            $("input[name='login_account_email']").val(data.login_account_email);
            $("input[name='login_account_tel']").val(data.login_account_tel);
            $("select[name='login_account_state']").val(data.login_account_state);
            form.render('select')
        }


        //监听提交
        form.on('submit(demo1)', function(result){
            $.post("/login/save",
                    result.field,
                    function (result) {
                        if(Number(result.result)>0){
                            if(data!=null){
                                layer.msg("修改成功");
                                parent.layer.closeAll();
                                parent.tableIns.reload();
                            }else{
                                layer.confirm("添加成功！需要继续添加吗？",function(index){
                                    $('#user-form')[0].reset();
                                    layer.close(index);
                                    parent.tableIns.reload();
                                },function(index){
                                    layer.close(index);
                                    parent.layer.closeAll();
                                    parent.tableIns.reload();
                                })
                            }
                        }
                    },"json"
            );
            return false;
        });

        $('#back-btn').on('click',function(){
            parent.layer.closeAll('iframe')
        });

    });
</script>
</body>
</html>